package com.king.zxing.app.fragments;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.king.zxing.app.R;
import com.king.zxing.app.dao.UserDao;
import com.king.zxing.app.domain.User;

import java.util.Objects;

//积分商城界面
public class IntegrationFragment extends Fragment {

    View view;

    long userID;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_integration, container, false);

        User user = Objects.requireNonNull(requireActivity().getIntent().getExtras()).getParcelable("user");
        assert user != null;

        userID = user.id;
        ((TextView) view.findViewById(R.id.integration_points)).setText(String.valueOf(user.getPoints()));

        return view;
    }

    @Override
    public void onResume() {
        super.onResume();

        String points = new UserDao(getContext()).getPointsByUserID(userID);
        ((TextView) view.findViewById(R.id.integration_points)).setText(points);
    }
}
